class PostSweeper < ActionController::Caching::Sweeper

  observe Post, Reply, User, Group, Community, Site

  def after_create(record)
    expire_record_page(record)
  end

  def after_update(record)
    expire_record_page(record)
  end

  def after_destroy(record)
    expire_record_page(record)
  end

  private
  def expire_record_page(record)
    case record
  	  when Post
        expire_fragment(:controller => "posts",
                      :action => "show",
			  	      :id     => record,
			  	      :part => 'content')
	  when Reply
        expire_action(:controller => "posts", 
                      :action => "show",
			  	      :id     => record.post)
	  when User
	    record.posts do |post|
        expire_action(:controller => "posts", 
                      :action => "show",
			  	      :id     => post)
		end
	  when Group
        record.posts do |post|
        expire_action(:controller => "posts", 
                      :action => "show",
			  	      :id     => post)
		end
	  when Community
        record.posts do |post|
        expire_action(:controller => "posts", 
                      :action => "show",
			  	      :id     => post)
		end
	  when Site
        record.posts do |post|
        expire_action(:controller => "posts", 
                      :action => "show",
			  	      :id     => post)
		end
    end
  end

end
